<template>
	<view 
		class="login-container"
		:style="{
			height:myHieght+'px',
			width:myWidth+'px',
			top:-20+'rpx',
			left:0
		}"
	>
		<view class="logo">
			<i class="iconfont icon-shu icon"></i>
			<h2>诗词颂</h2>
		</view>
		<view class="from">
			<view class="">
				<p>用户名:</p>
				<input type="text" @input="text" placeholder="请输入用户名"/>
			</view>
			<view class="">
				<p>密码:</p>
				<input type="password" @input="password" placeholder="请输入密码"/>
			</view>
		</view>
		<view class="login-forget" @click="goForget">
			注册/忘记密码
		</view>
		<view class="login-forget login-no" @click="goBack">
			返回
		</view>
		<button@click="_get_user_info">登录</button>
	</view>
</template>

<script>
	import {mapMutations,mapState} from 'vuex';
	export default {
		data() {
			return {
				isTrue:false,
				myHieght:0,
				myWidth:0,
				texts:'',
				passwords:''
			}
		},
		onLoad() {
			this.getSystemInfo();
		},
		methods: {
			getSystemInfo(){
				const res = uni.getSystemInfoSync();
				this.myHieght=res.screenHeight;
				this.myWidth=res.screenWidth;
			},
			goForget(){
				uni.showToast({
					title:'该功能未开放',
					icon:'none'
				})
			},
			async _get_user_info(){
				// const text = this.$refs.mytext.valueSync;
				// const password = this.$refs.mypassword.valueSync;
				// console.log(text,password)
				const {data} = await this.$http.get_user_info();
				for(let i=0;i<data.length;i++){
					if(data[i].userName==this.texts&&data[i].userPassword==this.passwords){
						this.updateUserInfo(data[i]);
						uni.navigateBack({})
						return;
					}
				}
				// console.log('asca')
				uni.showToast({
					icon:'error',
					title:'用户名/密码错误'
				})
				// console.log('asca')
			},
			goBack(){
				uni.navigateBack({})
			},
			text(e){
				// console.log(e)
				this.texts=e.detail.value;
				// console.log(this.texts)
			},
			password(e){
				this.passwords=e.detail.value;
			},
			...mapMutations(['updateUserInfo'])
		}
	}
</script>

<style scoped lang="scss">
@import './css/login.scss';
// @import '//at.alicdn.com/t/font_3243078_ym7305i66ol.css';
</style>
